<?php
namespace app\api\controller\v1;
use app\api\controller\Api;
class Init extends Api
{
	protected $checkaccess = true;
	protected $no_check_action = ['code'];
	protected $user = [];

	public function _initialize() {
		parent::_initialize();
		if($this->checkaccess === true) $this->checkAccess();
	}

	protected function checkAccess() {
		$action = $this->request->action();
		if ($this->no_check_action && in_array($action,$this->no_check_action)) {
			return true;
		}
		$token = $this->params['token'];

		if(empty($token)) {
			return $this->response('请登录后再操作', [], -99998);
		}
    	$this->user = model('user/user')->where(['token' => $token, 'status' => 1])->find();
		if (!$this->user) {
			return $this->response('用户不存在或已被禁用', [], -99997);
		}
		return true;
	}
}
